import java.util.zip.CheckedOutputStream;

public class PrintOddEven {
    private static final Object lock=new Object();
    private static int count=1;
    private static final int MAX_COUNT=10;

    public static void main(String[] args) throws InterruptedException {
        Runnable printOdd=()->{
            synchronized (lock){
                while (count<=MAX_COUNT){
                    if (count%2!=0){
                        System.out.println("Odd:"+count++);
                        lock.notify();
                        try {
                            lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        };
        Runnable printEvent=()->{
            synchronized (lock){
                while (count<=MAX_COUNT){
                    if (count%2==0){
                        System.out.println("Even:"+count++);
                        lock.notify();
                        try {
                            lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        };
        Thread oddThread=new Thread(printOdd,"OddThread");
        Thread evenThread=new Thread(printEvent,"EvenThread");
        oddThread.start();
        evenThread.start();
    }
}
